package com.example.backend.controller;

import com.example.backend.pojo.Address;
import com.example.backend.pojo.Result;
import com.example.backend.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/address")
public class AddressController {
    @Autowired
    private AddressService addressService;

    /**
     * 查询所有的省份或直辖市
     * @return
     */
    @GetMapping("/provinces")
    public Result<List<Address>> getProvinces(){
        List<Address> provinces = addressService.getProvinces();
        return Result.success(provinces);
    }

    /**
     * 根据所属地查询地址信息
     * @param addressRegionId 所属地编号
     * @return
     */

    @PostMapping("/city")
    public Result<List<Address>> getCities(Integer addressRegionId){
        List<Address> cities = addressService.getCities(addressRegionId);
        return Result.success(cities);
    }


}